<template>
  <header class="hi-header">
    <div class="statusBar" :style="{ height: `${statusBarHeight}px` }"></div>
    <div class="hi-header-title">
      <div v-if="leftVisible" :class="leftIconClass" @click="leftClick()">
        <i class="iconfont iconIc-goback" />
      </div>
      <div>{{ title }}</div>
      <div v-if="rightVisible" class="hi-header-right" @click="rightClick()">
        <slot></slot>
      </div>
    </div>
  </header>
</template>
<script>
export default {
  name: "NavBar",
  data() {
    return {
      statusBarHeight: 24,
    };
  },
  props: {
    title: {
      type: String,
      default: "",
    },
    leftVisible: {
      type: Boolean,
      default: true,
    },
    rightVisible: {
      type: Boolean,
      default: false,
    },
    leftIconClass: {
      type: String,
      default: "",
    },
  },
  created() {
    this.getStatusBarHeight();
  },
  methods: {
    leftClick() {
      this.$emit("leftClick");
    },
    rightClick() {
      this.$emit("rightClick");
    },
    //获取状态栏高度
    getStatusBarHeight() {
      let This = this;
      window.resultCallback = (res) => {
        This.statusBarHeight = JSON.parse(res).statusBarHeight || 24;
      };
      window.hilink &&
        window.hilink.getStatusBarHeight(
          "resultCallback" // resultCallback，成功或失败时，将调用传入resultStr返回结果
        );
    },
  },
};
</script>

<style lang="less" >
.hi-header {
  padding: 0 0.44444444rem 0 0.44444444rem !important;
  .hi-header-title {
    display: flex;
    align-items: center;
    height: 1.55555556rem;
    > div:first-child {
      // width: 0.66666667rem;
      i {
        font-size: 0.66666667rem;
        color: var(--font);
      }
    }
    > div:nth-child(2) {
      flex: 1;
      padding: 0 0.44444444rem;
      font-size: 0.66666667rem;
      line-height: 0.88666667rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: var(--font);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    > .hi-header-right {
      i {
        // font-size: 0.66666667rem;
        color: var(--font);
      }
    }
  }
}
</style>
